home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved */
- /*****************************************************************************/
- /* This source-code is NOT public domain nor Freeware, this is part of */
- /* 'The C Programming Package' which is Shareware. */
- /* If you use this code, please register and get a free Full-VGA version */
- /*****************************************************************************/
- /*------------------*
- * CPPLMATE.C *
- * Hardware config *
- *------------------*/
-
- /* Included Files */
- # include <stdio.h>
- # include <io.h>
- # include <dos.h>
- # include <fcntl.h>
- # include <bios.h>
- # include <stdlib.h>
- # include <SYS\stat.h>
- # include <conio.h>
- # include <alloc.h>
- # include <process.h>
- # include <ctype.h>
- # include <string.h>
-
- /* Global Variables */
- extern int x,y,z,i,j,k,l,m,n,bm,xm,ym;
- extern int colour1,colour2,colour3,colour4,colour5,cardtype;
- extern int pfserv,colourchoice,returning,printer;
- extern long dep;
- extern unsigned char c1,trashcan[],work[];
-
- /*-------------------*
- * OPEN WORKING FILE *
- *-------------------*/
- int open_working_file()
- {
- if(pfserv>-1) close(pfserv);
- strcpy(trashcan,work);
- if((strlen(trashcan)>3)) strcat(trashcan,"\\SERVICE.FIC");
- else strcat(trashcan,"SERVICE.FIC");
- pfserv=open(trashcan,O_RDWR | O_BINARY,S_IREAD|S_IWRITE);
- if(pfserv==-1){
- warning(" Cannot open"," the service file"," for the update","","");
- return(0);
- }
- dep=lseek(pfserv,0L,SEEK_SET); return(1);
- }
- /*--------------*
- * SAVE COLOURS *
- *--------------*/
- void save_the_colours()
- {
- z=open_working_file();
- if(z==0) return;
- /* If the file has been opened we save the colours in it */
- trashcan[3]=0x00; dep+=4;
- itoa(colour1,trashcan,10); lseek(pfserv,dep,0);
- write(pfserv,trashcan,3); dep+=3;
- itoa(colour2,trashcan,10); lseek(pfserv,dep,0);
- write(pfserv,trashcan,3); dep+=3;
- itoa(colour3,trashcan,10); lseek(pfserv,dep,0);
- write(pfserv,trashcan,3); dep+=3;
- itoa(colour4,trashcan,10); lseek(pfserv,dep,0);
- write(pfserv,trashcan,3); dep+=3;
- itoa(colour5,trashcan,10); lseek(pfserv,dep,0);
- write(pfserv,trashcan,3);
- close(pfserv); pfserv=-1;
- }
- /*-------------------*
- * GET SPECIAL COLOR *
- *-------------------*/
- int get_special_colour()
- {
- if(c1==59){
- /* F1 = On-Line help */
- return(59);
- }
- if(c1==72){
- /* Up arrow */
- if(colourchoice>1) colourchoice--;
- }
- if(c1==80){
- /* Down arrow */
- if(colourchoice<7) colourchoice++;
- }
- if(c1==75){
- /* Left arrow */
- if(colourchoice==7) colourchoice--;
- }
- if(c1==77){
- /* Right arrow */
- if(colourchoice==6) colourchoice++;
- }
- /* In all the other cases we change nothing */
- /* But we return the value 0 */
- /* because arrows need to be confirmed with <Enter> */
- return(0);
- }
- /*------------------*
- * GET COLOUR MOUSE *
- *------------------*/
- int get_colour_mouse()
- {
- if((xm>61)&&(xm<68)){
- /* We are in the 'useful' menu zone */
- if(ym==17) return(11);
- if(ym==18) return(12);
- if(ym==19) return(13);
- if(ym==20) return(14);
- if(ym==21) return(15);
- }
- if(ym==23){
- /* With the mouse it is choice & confirmation */
- if((xm>61)&&(xm<70)) return(16);
- if((xm>70)&&(xm<80)) return(17);
- }
- /* In all the other cases we return 0 */
- return(0);
- }
- /*----------------------*
- * DISPLAY COLOR CHOICE *
- *----------------------*/
- void display_colour_choice()
- {
- hide_the_mouse(); textattr(colour4);
- gotoxy(62,17); cputs(" 1 ");
- gotoxy(62,18); cputs(" 2 ");
- gotoxy(62,19); cputs(" 3 ");
- gotoxy(62,20); cputs(" 4 ");
- gotoxy(62,21); cputs(" 5 ");
- gotoxy(62,23); cputs(" Confirm");
- gotoxy(71,23); cputs("Esc Quit ");
- /* Outline the current one */
- textattr(colour5);
- if(colourchoice==1){
- gotoxy(62,17); cputs(" 1 ");
- }
- if(colourchoice==2){
- gotoxy(62,18); cputs(" 2 ");
- }
- if(colourchoice==3){
- gotoxy(62,19); cputs(" 3 ");
- }
- if(colourchoice==4){
- gotoxy(62,20); cputs(" 4 ");
- }
- if(colourchoice==5){
- gotoxy(62,21); cputs(" 5 ");
- }
- if(colourchoice==6){
- gotoxy(62,23); cputs(" Confirm ");
- }
- if(colourchoice==7){
- gotoxy(71,23); cputs("Esc Quit ");
- }
- /* And display the colours in the case they had been */
- /* changed during the previous choice */
- textattr(colour1);
- gotoxy(69,17); cputs(" colour1 ");
- textattr(colour2);
- gotoxy(69,18); cputs(" colour2 ");
- textattr(colour3);
- gotoxy(69,19); cputs(" colour3 ");
- textattr(colour4);
- gotoxy(69,20); cputs(" colour4 ");
- textattr(colour5);
- gotoxy(69,21); cputs(" colour5 ");
- show_the_mouse();
- }
- /*----------------*
- * PRINTER CHOICE *
- *----------------*/
- void printer_choice()
- {
- returning=open_working_file();
- if(returning==0) return;
- save_screen2(35,4); textattr(colour4);
- hide_the_mouse(); dep+=34;
- /* Get the choice stored in the file */
- lseek(pfserv,dep,0); read(pfserv,trashcan,1);
- trashcan[1]=0x00;
- gotoxy(37,4); cputs("╔══════════════════════╗");
- gotoxy(37,5); cputs("║ PRINTER CHOICE ║");
- gotoxy(37,6); cputs("║ Current choice= ║");
- gotoxy(37,7); cputs("╟──────────────────────╢");
- gotoxy(37,8); cputs("║ 0 - Non graphics ║");
- gotoxy(37,9); cputs("║ 1 - Epson/IBM graphic║");
- gotoxy(37,10); cputs("║ 2 - HP Deskjet ... ║");
- gotoxy(37,11); cputs("║ 3 - HP Laserjet ... ║");
- gotoxy(37,12); cputs("║ 4 - CANON Laser BJ ║");
- gotoxy(37,13); cputs("║ <Esc> No Change ║");
- gotoxy(37,14); cputs("║ ║");
- gotoxy(37,15); cputs("╚══════════════════════╝");
- textattr(colour5); sound1();
- gotoxy(54,6); cputs(trashcan);
- gotoxy(44,14); cputs(" Your choice : ");
- show_the_mouse(); returning=wait_for_a_key();
- /* Treat the result */
- if(returning==100){
- /* We clicked */
- if((xm>37)&&(xm<60)){
- /* We are in the 'useful' menu zone */
- if(ym==8) returning=0;
- if(ym==9) returning=1;
- if(ym==10) returning=2;
- if(ym==11) returning=3;
- if(ym==12) returning=4;
- }
- else returning=5;
- /* In all the others case we return = Esc without change */
- }
- if(returning<5){
- /* Store the new choice in the printer variable */
- /* And save it in the service file */
- printer=returning;
- itoa(returning,trashcan,10); trashcan[1]=0x00;
- lseek(pfserv,dep,0); write(pfserv,trashcan,1);
- if(pfserv>-1) close(pfserv);
- pfserv=-1;
- }
- /* Restore the initial screen and go back to the menu */
- restore_screen2(35,4); return;
- }
- /*----------------*
- * COLOURS CHOICE *
- *----------------*/
- void colour_choice()
- {
- hide_the_mouse(); save_screen2(55,14);
- colourchoice=1; textattr(colour4);
- gotoxy(61,14); cputs("╔══════╤═══════════╗");
- gotoxy(61,15); cputs("║Choice│ Colours ║");
- gotoxy(61,16); cputs("╟──────┼───────────╢");
- gotoxy(61,17); cputs("║ 1 │ ║");
- gotoxy(61,18); cputs("║ 2 │ ║");
- gotoxy(61,19); cputs("║ 3 │ ║");
- gotoxy(61,20); cputs("║ 4 │ ║");
- gotoxy(61,21); cputs("║ 5 │ ║");
- gotoxy(61,22); cputs("╠══════╧═╤═════════╣");
- gotoxy(61,23); cputs("║ Confirm│Esc Quit ║");
- gotoxy(61,24); cputs("╚════════╧═════════╝");
- show_the_mouse(); sound1();
- /* Do nothing until <Esc> is pressed to quit without change */
- /* or <Enter> is pressed to confirm changes */
- while(1){
- /* Do nothing until a key is pressed */
- /* or we pressed a mouse button. */
- display_colour_choice();
- while(1){
- if(kbhit()){
- /* If we pressed a key */
- c1=getch();
- if(c1==0){
- /* Key coded on 2 bytes. Cut the second one. */
- c1=getch();
- returning=get_special_colour(); break;
- }
- else{
- /* We pressed a key */
- returning=get_key();
- if(returning==31) returning=6;
- if(returning==26) returning=7;
- break;
- }
- }
- /* Else test the mouse */
- get_mouse_state();
- if(bm==1){
- /* We pressed a mouse button */
- returning=get_colour_mouse(); break;
- }
- }
- /* We treat the result */
- /* Between 1 and 7, we chose a non active line */
- if((returning>0)&&(returning<8)) colourchoice=returning;
- if(returning==40){
- /* We pressed <Enter> */
- /* If it is a colour we change it */
- if((colourchoice>0)&&(colourchoice<6)){
- if((cardtype==1)||(cardtype==3)||(cardtype==4)||(cardtype==5)||(cardtype==9)){
- /* It is a colour card */
- choose_a_colour();
- }
- else choose_mono_colour();
- textattr(colour1); hide_the_mouse();
- window(2,3,59,24); clrscr();
- window(1,1,80,25); show_the_mouse();
- }
- if(colourchoice==6){
- /* It is the choice 'save changes' */
- save_the_colours(); break;
- }
- }
- if((returning>10)&&(returning<16)){
- /* Between 11 and 15 we chose a line + action (mouse) */
- colourchoice=returning-10;
- if((cardtype==1)||(cardtype==3)||(cardtype==4)||(cardtype==5)||(cardtype==9)){
- /* It is a colour card */
- choose_a_colour();
- }
- else choose_mono_colour();
- textattr(colour1); hide_the_mouse();
- window(2,3,59,24); clrscr();
- window(1,1,80,25); show_the_mouse();
- }
- if(returning==16){
- /* We clicked on the save case */
- save_the_colours(); break;
- }
- /* We pressed <Esc> or <Enter> above Quit */
- /* We want to quit the sub-program without saving */
- if((returning==-1)||((returning==40)&&(colourchoice==7))) break;
- if(returning==59){
- /* We want a specific help for this sub-menu */
- display_help("CONFIGUR",92,4,1); restore_help_screen();
- }
- }
- textattr(colour1); hide_the_mouse();
- window(2,3,59,24); clrscr();
- window(1,1,80,25); restore_screen2(55,14);
- show_the_mouse();
- }
- /* End of the hardware config file */
-